<?php
function rc4($pwd,$data,$method = 'en') {
    if($method == 'de') {
        $data = hex2bin(base64_decode($data));
    };
    $key[] = '';
    $box[] = '';
    $pwd_length = strlen($pwd);
    $data_length = strlen($data);
    $cipher = '';
    for($i = 0; $i < 256; $i++) {
        $key[$i] = ord($pwd[$i % $pwd_length]);
        $box[$i] = $i;
    };
    for ($j = $i = 0; $i < 256; $i++) {
        $j = ($j + $box[$i] + $key[$i]) % 256;
        $tmp = $box[$i];
        $box[$i] = $box[$j];
        $box[$j] = $tmp;
    };
    for ($a = $j = $i = 0; $i < $data_length; $i++) {
        $a = ($a + 1) % 256;
        $j = ($j + $box[$a]) % 256;
        $tmp = $box[$a];
        $box[$a] = $box[$j];
        $box[$j] = $tmp;
        $k = $box[(($box[$a] + $box[$j]) % 256)];
        $cipher .= chr(ord($data[$i]) ^ $k);
    }
    if($method == 'en') {
        return base64_encode(bin2hex($cipher));
    } else {
        return $cipher;
    };
}
function token($str,$model = 'en') {
    if($model == 'en') {
        return strtoupper(bin2hex(base64_encode(gzencode($str))));
    };
    if($model == 'de') {
        return gzdecode(base64_decode(hex2bin(strtolower($str))));
    };
};
function GeJIsafe($str,$method = 'en') {
    global $set;
    if($method == 'en') {
        return rc4(md5($_SERVER['HTTP_HOST'].$set['encode'].'GeJI'),token($str));
    };
    if($method == 'de') {
        return token(rc4(md5($_SERVER['HTTP_HOST'].$set['encode'].'GeJI'),$str,'de'),'de');
    };
};
function en($str,$m) {
    $M = md5($_SERVER['REMOTE_ADDR']);
    $r = str_replace('A','~',base64_encode($str));
    $r = str_replace('B',':',$r);
    $r = str_replace('C','-',$r);
    $r = str_replace('D','@',$r);
    $r = str_replace('F','#',$r);
    $r = str_replace('G','%',$r);
    $r = str_replace('H',"'",$r);
    $r = str_replace('J','&',$r);
    $r = str_replace('K','*',$r);
    $r = str_replace('L','?',$r);
    $r = str_replace('M',$M,$r);
    $r = str_replace('N',';',$r);
    $r = str_replace('S','!',$r);
    $r = str_replace('V','_',$r);
    $r = str_replace('X',')',$r);
    $r = str_replace('Z','(',$r);
    if($m == 'M') {
        return $M;
    } else {
        return $r;
    };
};